<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>get_test</title>

    <script src="/jquery-3.5.1.min.js"></script>
    <script src="/main.js"></script>
</head>
<body>
    <button id="btn_get_baidu">获取百度网页源码</button>
    <button id="btn_get_json">JSON数据解析</button>
    <button id="btn_get_header">获取header信息</button>
    <button id="btn_get_cookie">百度ck获取</button>
    <button id="btn_get_inner_cookie">构造器缓存ck获取</button>
    <div style="word-wrap: break-word"></div>

<script>
    let smm=$.moon();
    $("#btn_get_baidu").click(function () {
        smm.get("https://www.baidu.com",function (data) {
            $("div").text(data);
        });
    });
    $("#btn_get_json").click(function () {
        smm.get("http://ip-api.com/json/115.191.200.34?lang=zh-CN",function (data,rawdata) {
            $("div").html("该IP所属城市"+data.city+"<br/>"+"-------------原始信息--------------<br/>"+rawdata.data);
        });
    });
    $("#btn_get_header").click(function () {
        smm.get("https://www.taobao.com/",function (data,rawdata) {
            let out="";
            for (let i = 0; i < rawdata.header.length; i++) {
                let h=rawdata.header[i];
                out=out+h.name+": "+h.value+"<br/>";
            }
            $("div").html(out);
            //$("div").html("该IP所属城市"+data.city+"<br/>"+"-------------原始信息--------------<br/>"+rawdata.data);
        });
    });
    $("#btn_get_cookie").click(function () {
        smm.get("https://www.baidu.com/",function (data,rawdata) {
            let out = "";
            console.log(rawdata);
            for (let i = 0; i < rawdata.header.length; i++) {
                let h = rawdata.header[i];
                if (h.name == "Set-Cookie") {
                    for (let j = 0; j < h.elements.length; j++) {
                        let elementsKey=h.elements[j];
                        out = out + elementsKey.name + "=" + elementsKey.value + "; ";
                    }
                }
            }
            $("div").html(out);
        })
    })
    $("#btn_get_inner_cookie").click(function () {
        $("div").html("<br/>如果没有获取到数据，请先点击任意一个访问百度的按钮"+"<br/>"+smm.getRawCookie());
    })




</script>
</body>
</html>